<?php

// 网站系统设置

namespace app\console\controller;

use think\Url;
use think\Request;
use think\Controller;
use app\console\model\Config as ConfigModel;
use app\console\model\ConfigType as ConfigTypeModel;

class Config extends Controller
{
    /**
     * 系统设置
     */
    public function index()
    {
        // 修改配置项
        if (Request::instance()->isPost()) {

            // 实例化
            $ConfigModel = new ConfigModel();

            // 调用 配置项更新数据 方法
            if ($ConfigModel->renew()) {
                win('更新成功', Url::build('config/index'));
            } else {
                fail('更新失败');
            }

        }

//        // 获取所有配置类型的配置文件
        $data = (new ConfigTypeModel())->with('Config')->where(['sun_config_type.status'=>1])->select()->toArray();
//        $web_special_price_pic = db('config')->where(['varname'=>'web_special_price1'])->value('varvalue');
//        $web_hot_selling_pic1 = db('config')->where(['varname'=>'web_hot_selling1'])->value('varvalue');
//        $web_brand_street_pic1 = db('config')->where(['varname'=>'web_brand_street1'])->value('varvalue');


        return $this->fetch('', [
            'mate_title' => '系统设置',
            'data'       => $data,

        ]);
    }



    /**
     * 添加新变量
     */
    public function addVariables()
    {
        // 新增变量
        if (Request::instance()->isPost()) {

            $ConfigModel = new ConfigModel();

            if ($ConfigModel->newVariable()) {
                win('添加成功', Url::build('config/index'));
            } else {
                fail('添加失败');
            }
        }

    }
}